package org.example.tails.util;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtil {
    public static String generateToken(Map<String,Object> map){
        String jwt= Jwts.builder().
                signWith(SignatureAlgorithm.HS256,"itheima").
                addClaims(map).
                setExpiration(new Date(System.currentTimeMillis()+3600000)).
                compact();
        return jwt;
    }

    public static Claims parseToken(String token) throws Exception{
        Claims claims=Jwts.parser().
                setSigningKey("itheima").
                parseClaimsJws(token).
                getBody();
        return claims;
    }
}
